package cn.caojun.auth.service.Impl;

import cn.caojun.auth.domain.Role;
import cn.caojun.auth.dto.RoleMenuDTO;
import cn.caojun.auth.dto.RolePermissionDTO;
import cn.caojun.auth.mapper.RoleMapper;
import cn.caojun.auth.query.RoleQuery;
import cn.caojun.auth.service.IRoleService;
import cn.caojun.basic.service.impl.BaseServiceImpl;
import cn.caojun.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    @Transactional
    public void setRolePermission(RolePermissionDTO rolePermissionDTO) {
        roleMapper.deletePermissionById(rolePermissionDTO.getRoleId());
        roleMapper.addRolePermission(rolePermissionDTO.getRoleId(),rolePermissionDTO.getPermissionSns());
    }

    @Override
    public List<String> getPermissionById(Long roleId) {
        return roleMapper.loadPermissionById(roleId);
    }

    @Override
    public List<String> getMenuById(Long roleId) {
        return roleMapper.loadMenuById(roleId);
    }

    @Override
    public void setRoleMenu(RoleMenuDTO roleMenuDTO) {
        roleMapper.deleteMenuById(roleMenuDTO.getRoleId());
        roleMapper.addRoleMenu(roleMenuDTO.getRoleId(),roleMenuDTO.getMenuId());
    }
}
